﻿using Microsoft.AspNetCore.SignalR;
using Plugins.SignalR;
using System.Threading.Tasks;

namespace DotNetCoreApi.Plugins.SignalR
{


    /// <summary>
    /// SignR帮助类
    /// </summary>
    public class SignRHelper
    {
        /// <summary>
        /// 发送给所有人
        /// </summary>
        public IHubContext<SignalRHub> countHub { get; set; }
        public async  Task SendAll(string msg, string id)
        {
            await countHub.Clients.All.SendAsync("AddMsg", $"{id}：{msg}");
        }
        /// <summary>
        /// 发送给某人
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="id"></param>
        /// <param name="toId"></param>
        /// <returns></returns>
        public async Task SendTo(string msg, string id,string toId)
        {
            await countHub.Clients.Client(toId).SendAsync("AddMsg", $"[{id}]-[{toId}]：{msg}");
        }
    }
}
